package vy.org.app.page.printlabel.report.schedule;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.vy.dal.dao.VyPrintLabelReportDAO;
import org.vy.dal.dao.VyPrintLabelReportDO;

import vy.org.app.common.BaseAction;
import vy.org.app.common.ModuleEnum;

public class SavePrintLabelReportScheduleAction extends BaseAction {

	@Override
	public ActionForward executeAction(ActionMapping mapping,
			ActionForm actionForm, HttpServletRequest request,
			HttpServletResponse response) {
		MntnPrintLabelReportScheduleForm form = (MntnPrintLabelReportScheduleForm)actionForm;
		try{
			VyPrintLabelReportDO dto = PrintLabelReportHelper.fillReportDO(form);
			if(form.getReportId() ==null || "".equals(form.getReportId())
					|| "0".equals(form.getReportId())){
				dto.setReportId(0);
				VyPrintLabelReportDAO.insert(dto);
			}else if( form.getReportId() != null && !"".equals(form.getReportId())
					&& ("EDIT".equalsIgnoreCase(form.getOps())
					|| "ADD".equalsIgnoreCase(form.getOps()))){
				VyPrintLabelReportDAO.update(dto);
			}else if("DELETE".equalsIgnoreCase(form.getOps())){
				VyPrintLabelReportDAO.delete(dto);
			}
			form.setAck("SUCCESS");
		}catch(Exception e){
			form.setAck("FAILURE");
			return mapping.findForward("failure");
		}
		
		return mapping.findForward("success");
	}

	@Override
	protected ModuleEnum getModuleId() {
		return ModuleEnum.MNTN_PRINT_LABEL_REPORT;
	}

}
